package com.novel.service.impl.review;

import com.novel.entiy.Chapter;
import com.novel.entiy.Novel;
import com.novel.entiy.TpUser;
import com.novel.entiy.dto.ReviewDTO;
import com.novel.mapper.ChapterMapper;
import com.novel.mapper.NovelMapper;
import com.novel.mapper.TpUserMapper;
import com.novel.service.NovelService;
import com.novel.service.ReviewService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.mail.internet.MimeMessage;
import java.util.Date;

/**
 * @author tanghao
 * @date 2022/4/16
 */
@Slf4j
@Service
public class ChapterReviewServiceImpl implements ReviewService {

    @Resource
    private NovelMapper novelMapper;

    @Resource
    private TpUserMapper tpUserMapper;

    @Resource
    private ChapterMapper chapterMapper;

    @Resource
    private NovelService novelService;

    /**
     * 同意审批
     *
     * @param reviewDTO 审批参数
     */
    @Override
    public void agreeReview(ReviewDTO reviewDTO) {
        log.info("章节同意审批  {}", reviewDTO);
        Chapter chapter = chapterMapper.selectById(reviewDTO.getMainId());
        chapter.setStatus(1);
        chapterMapper.updateById(chapter);
        novelService.updateNovel(chapter);
    }

    /**
     * 审批失败
     *
     * @param reviewDTO 审批参数
     */
    @Override
    public void rejectReview(ReviewDTO reviewDTO) {
        log.info("章节审批失败  {}", reviewDTO);
        Chapter chapter = chapterMapper.selectById(reviewDTO.getMainId());
        chapter.setStatus(3);
        chapterMapper.updateById(chapter);
    }
}
